﻿


using SqlSugar;
using System.Configuration;

namespace GameHubService;

/// <summary>
/// 数据库操作基类
/// </summary>
public class SqlSugarRepository<T> : SimpleClient<T> where T : class, new() {



    public SqlSugarRepository() { 


        string connectionString =  ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

        this.Context = new SqlSugarClient(new ConnectionConfig() {
            ConnectionString = connectionString,
            DbType = DbType.Sqlite,
            IsAutoCloseConnection = true
        });

        // 判断数据库和表是否存在，如果不存在则创建
        if (!this.Context.DbMaintenance.IsAnyTable(typeof(T).Name)) {
            this.Context.CodeFirst.InitTables(typeof(T));
        } 
    }
}

